package validate;

import constant.Msg;
import util.AppUtil;
import model.User;

public class UserValidate {
	public static String get(int userid, String id) {
		if (!(User.dao.selectById(userid) != null))
			return Msg.ERROR_ID_UNEXISTED;
		if(id==null)
			return Msg.ERROR_PARA_NUM;
		if(!AppUtil.isInteger(id))
			return Msg.ERROR_PARA_TYPE;
		if (!(User.dao.selectById(Integer.parseInt(id)) != null))
			return Msg.ERROR_ID_UNEXISTED;
		return null;
	}

	public static String post(String code) {
		if (code == null)
			return Msg.ERROR_PARA_NUM;
		return null;
	}

	public static String put(int id) {
		if (!(User.dao.selectById(id) != null))
			return Msg.ERROR_ID_UNEXISTED;
		return null;
	}

	public static String avatar(String avatar) {
		if (avatar == null)
			return Msg.ERROR_PARA_NUM;
		return null;
	}

	public static String sms(String phone) {
		if (phone == null)
			return Msg.ERROR_PARA_NUM;
		if (!AppUtil.isphone(phone))
			return Msg.ERROR_PATTERN;
		return null;
	}
	
	public static String bind(String phone, String code){
		if(phone == null || code == null)
			return Msg.ERROR_PARA_NUM;
		if(!AppUtil.isphone(phone))
			return Msg.ERROR_PATTERN;
		if(!(AppUtil.isInteger(code) && code.trim().length()==4))
			return Msg.ERROR_PATTERN;
		return null;
	}
}
